package com.example.zuoye.mvp.view.fragment;


import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.mylibrary.mvp.view.BaseFragment;
import com.example.zuoye.R;
import com.example.zuoye.adapter.FormAdapter;
import com.example.zuoye.bean.PostBodyBean;
import com.example.zuoye.bean.TagTravel;
import com.example.zuoye.bean.UserBean;
import com.example.zuoye.mvp.contract.MainContract;
import com.example.zuoye.mvp.contract.PostContract;
import com.example.zuoye.mvp.model.MainModel;
import com.example.zuoye.mvp.model.PostModel;
import com.example.zuoye.mvp.presenter.MainPresenter;
import com.example.zuoye.mvp.presenter.PostPresenter;
import com.scwang.smartrefresh.header.DeliveryHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ListFragment extends BaseFragment<PostPresenter> implements PostContract.View {
    private int type;

    public ListFragment(int type) {
        this.type = type;
    }

    private SmartRefreshLayout sl;
    private RecyclerView rv;

    @Override
    public int bondLayout() {
        return R.layout.fragment_list;
    }

    @Override
    public void initView() {

        sl = (SmartRefreshLayout) findViewById(R.id.sl);
        rv = (RecyclerView) findViewById(R.id.rv);
        rv.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
        rv.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));

        //上下拉刷新
        sl.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                sl.finishLoadMore();
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                sl.finishRefresh();
            }
        });
        sl.setRefreshHeader(new DeliveryHeader(getContext()));

    }


    @Override
    public void initData() {
       mPresenter=new PostPresenter(new PostModel(),this);
       mPresenter.requestForm();
    }


    @Override
    public void loadLayout() {

    }

    @Override
    public void hideLayout() {

    }

    @Override
    public void Toast(String message) {

    }

    @Override
    public void initForm(List<TagTravel> list) {
        FormAdapter formAdapter = new FormAdapter(R.layout.item, list);
        rv.setAdapter(formAdapter);
    }

    @Override
    public void initBody(List<PostBodyBean> list) {

    }
}
